from django.db import models
from basedata.models import City, Feature, Fitting


class House(models.Model):
    HOUSE_CATEGORY_SALE = 'S'
    HOUSE_CATEGORY_RENT = 'R'
    HOUSE_CATEGORY_CHOICES = ((HOUSE_CATEGORY_SALE, '售房'),
                              (HOUSE_CATEGORY_RENT, "租房"))
    name = models.CharField('小区名称', max_length=100)
    address = models.CharField('地址', max_length=300)
    rent_money = models.PositiveIntegerField('金额', default=0)
    size = models.FloatField('平米数', default=0)
    position = models.CharField('位置朝向', null=True, blank=True, max_length=50)
    decorate = models.CharField('装修情况', null=True, blank=True, max_length=50)
    rent_way = models.CharField('租住方式', null=True, blank=True, max_length=50)
    type = models.CharField('房屋类型', null=True, blank=True, max_length=50)
    layout = models.CharField('房屋布局', null=True, blank=True, max_length=50)
    category = models.CharField('发布类别', max_length=1, choices=HOUSE_CATEGORY_CHOICES, default=HOUSE_CATEGORY_SALE)
    floor_num = models.PositiveSmallIntegerField('楼层数', default=0)
    floor_total = models.PositiveSmallIntegerField('总楼层数', default=0)
    info = models.CharField('描述', null=True, blank=True, max_length=4000)
    city = models.ForeignKey(City)
    house_features = models.ManyToManyField(Feature)
    house_fittings = models.ManyToManyField(Fitting)


class HouseImage(models.Model):
    house_pic = models.ImageField('房子照片', upload_to='house', null=True)
    house = models.ForeignKey(House)
